home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / ast_comp / cpp-kit.lha / c++kit / main.C next >
C/C++ Source or Header  |  1993-04-11  |  837b  |  56 lines

  1. #include <iostream.h>
  2. #include "Parse.H"
  3. #include <ctype.h>
  4.  
  5. int
  6. number(Parse &P, int& value)
  7. {
  8. Token tok;
  9.  
  10.    P, NUMBER(tok);
  11.    if( P ) {
  12.    int i = isdigit(tok[0])?0:1;
  13.       for( value = 0; i < tok.length(); i++ ) {
  14.      value = value * 10 + (tok[i] - '0');
  15.       }
  16.       if( tok[0] == '-' ) {
  17.      value = -value;
  18.       }
  19.    }
  20.    return P;
  21. }
  22.  
  23. int
  24. Break(Parse& P)
  25. {
  26. int   fleet;
  27. int   amt;
  28.  
  29.    P , 'B', MATCH(number, fleet), MATCH(number, amt), CHOOSE(1),
  30.    OR, 'B', "MAX", MATCH(number, amt), CHOOSE(2);
  31.  
  32.    switch(P()) {
  33.    case 0: {
  34.      cout << "no match" << endl;
  35.      break;
  36.       }
  37.    case 1: {
  38.      cout << fleet << ' ' << amt << endl;
  39.      break;
  40.       }
  41.    case 2: {
  42.      cout << "MAX " << amt << endl;
  43.      break;
  44.       }
  45.    }
  46.    return P;
  47. }
  48.  
  49. main()
  50. {
  51. Parse      P("foo");
  52. Token      x;
  53.    P, MATCH(Break);
  54.    cout << P << ' ' << P() << endl;
  55. }
  56.